/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.geektimes.http.server.jdk.servlet;

import java.util.Collection;
import java.util.Comparator;

/**
 * URL Patterns Matcher
 *
 * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
 * @author leo
 * @since 1.0.0
 */
public interface URLPatternsMatcher {

    PriorityComparator PRIORITY_COMPARATOR = new PriorityComparator();

    /**
     * 功能: url pattern 组合 {@link javax.servlet.ServletRegistration.Dynamic#addMapping(String...)}.
     * <br> 作者: leo
     * <br>创建日期:2021/7/1
     * <br>修改者: mender
     * <br>修改日期: modify date
     * @param urlPatterns url mapping
     * @param requestURI 请求URI
     * @return boolean 是否匹配
    */
    boolean matches(Collection<String> urlPatterns, String requestURI);

    /**
     * 多个mather的排序 default {@link Integer#MIN_VALUE}
     * @return
     */
    default int getOrder(){
        return Integer.MIN_VALUE;
    }

    class PriorityComparator implements Comparator<URLPatternsMatcher> {
        @Override
        public int compare(URLPatternsMatcher o1, URLPatternsMatcher o2) {
            return Integer.compare(o1.getOrder(),o2.getOrder());
        }
    }
}


